package fm.dongman.animefm.view.util

import android.app.Activity
import android.content.Context
import android.view.WindowManager

/**
 * 系统工具类
 * Created by shize on 2017/10/14.
 */
object SystemHelper {
    /**
     * 获取状态栏高度
     * @param context 上下文
     * @return 返回高度值 px
     */
    fun getStatusBarHeight(context: Context): Int {
        var result = 0
        val resourceId = context.resources.getIdentifier("status_bar_height", "dimen", "android")
        if (resourceId > 0) {
            result = context.resources.getDimensionPixelSize(resourceId)
        }
        return result
    }

    /**
     * 从dp转换为px

     * @param context  上下文
     * *
     * @param dipValue dp值
     * *
     * @return px值
     */
    fun dipToPx(context: Context, dipValue: Float): Float {
        // 获取比例
        val scale = context.resources.displayMetrics.density
        return dipValue * scale + 0.5f
    }

    /**
     * 从px转换为dp

     * @param context 上下文
     * *
     * @param pxValue px值
     * *
     * @return dp值
     */
    fun pxToDip(context: Context, pxValue: Float): Float {
        // 获取比例
        val scale = context.resources.displayMetrics.density
        return pxValue / scale + 0.5f
    }

    /**
     * 设置全屏
     */
    fun setFullScreen(activity: Activity) {
        activity.window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN)
    }

    /**
     * 退出全屏
     */
    fun quitFullScreen(activity: Activity){
        val attrs = activity.window.attributes
        attrs.flags = attrs.flags and WindowManager.LayoutParams.FLAG_FULLSCREEN.inv()
        activity.window.attributes = attrs
        activity.window.clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
    }
}